﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.FILAPI;

namespace FilStartUps.Controls
{
    public partial class FilStartUps_News : System.Web.UI.UserControl
    {
        private void GetLatestNews()
        {
            try
            {
                var news = FilStartUpsAPI.GetNewsPost();
                dlFilStartUpsNews.DataSource = news;
                dlFilStartUpsNews.DataBind();
            }
            catch (Exception)
            {

            }
        }

        public string Truncate(string Description)
        {
            string desc;
            try
            {
                desc = Description.ToString().Substring(0, 200) + "....";
            }
            catch (Exception)
            {
                desc = Description;
            }

            return desc;
        }

        public string ConvertDate(string date)
        {
            string date_;
            try
            {
                DateTime _date = Convert.ToDateTime(date);
                date_ = _date.ToShortDateString();//String.Format("{0:d/M/yyyy}", date);
            }
            catch
            {
                date_ = date.ToString();
            }
            return date_;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetLatestNews();
            }
        }

        //TODO
        //Response.Redirect("Article.aspx");
        protected void dlFilStartUpsNews_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            if (e.CommandName == "SelectRow")
            {
                Label lbpost = (Label)dlFilStartUpsNews.Items[e.Item.ItemIndex].FindControl("postidPK");
                Response.Redirect("~/Article.aspx?p=" + lbpost.Text);
            }

        }
        protected void btnrss_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/rss.aspx?ID=2");
        }
    }
}